const config = require('../../config.js')
function http() {}
http.prototype.post = async function(url, data) {
	var datas = data || {}
	url = url.indexOf('https://') !== -1 ? url : config.baseUrl + url
	return await new Promise(function (resolve, reject) {
		var data = {
			url: url,
			data: datas,
			method: 'POST',
			success: (res) => {
				if (res.statusCode === 200) {
					resolve(res.data)
				} else {
					reject(res)
				}
			},
			fail: (err) => {
				console.log(err)
				reject(err)
			}
		}
		uni.request(data)
	})
}
http.prototype.get = async function(url, data) {
	var datas = data || {}
	url = url.indexOf('https://') !== -1 ? url : config.baseUrl + url
	return await new Promise(function (resolve, reject) {
		var data = {
			url: url,
			data: datas,
			method: 'GET',
			success: (res) => {
				if (res.statusCode === 200) {
					resolve(res.data)
				} else {
					reject(res)
				}
			},
			fail: (err) => {
				console.log(err)
				reject(err)
			}
		}
		uni.request(data)
	})
}
http.prototype.request = async function(obj) {
	var obj = obj
	return await new Promise(function (resolve, reject) {
		obj.success = (res) => {
			if (res.statusCode === 200) {
				resolve(res.data)
			} else {
				reject(res)
			}
		}
		obj.fail = (err) => {
			console.log(err)
			reject(err)
		},
		uni.request(obj)
	})
}
export default http
// export default {}